//==============================================================================
#include "CApp.h"

//==============================================================================
void CApp::OnEvent(SDL_Event* Event) {
	CEvent::OnEvent(Event);
}

//==============================================================================
void CApp::OnExit() {
	Running = false;
}

//==============================================================================
/*
void CApp::OnLButtonDown(int mX, int mY) {

int i = (mX/drawStepW);
int j = ((w_height - mY)/drawStepH);

u[INDEX(i,j)] = force * (mX - omx);
v[INDEX(i,j)] = force * (mY - omy);

omx = mX;
omy = mY;
}

void CApp::OnRButtonDown(int mX, int mY) {
int i = (mX/drawStepW);
int j = ((w_height - mY)/drawStepH);
density[INDEX(i,j)] = force;

omx = mX;
omy = mY;
}*/


void CApp::OnMouseMove(int mX, int mY, int relX, int relY, bool Left,bool Right,bool Middle){


	if ( Left && Right ) return;

	int i = (int)((       mX /(float)w_width)*N+1);
	int j = (int)(((w_height-mY)/(float)w_height)*N+1);

	if ( i<1 || i>N || j<1 || j>N ) return;

	if ( Right ) {
		u[INDEX(i,j)] = force * (mX-omx);
		v[INDEX(i,j)] = force * (omy-mY);
	}

	if ( Left ) {
		density[INDEX(i,j)] = source;
	}

	omx = mX;
	omy = mY;

	return;
}



void CApp::OnKeyDown(SDLKey sym, SDLMod mod, Uint16 unicode) {
	switch (sym)
	{
	case SDLK_ESCAPE:
		exit(-1);
		break;
	case SDLK_c:

		int i;

		for ( i=0 ; i<SIZE ; i++ ) 
		{
			u[i] = v[i] = u_previous[i] = v_previous[i] = density[i] = density_previous[i] = 0.0f;
		}
		break;
	case SDLK_d:
		showDensity = !showDensity;
		break;

	case SDLK_g:
		gravity = !gravity;
		break;

	case SDLK_v:
		RenderMode =  RenderMode == GL_QUADS ? GL_LINE_LOOP:GL_QUADS;
		break;

	default:
		break;
	}
}

void CApp::OnKeyUp(SDLKey sym, SDLMod mod, Uint16 unicode) {
}